package com.dlmz.view;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class MenuJframe extends JFrame implements ActionListener{
	public static void main(String[] args)   
    {  
        // TODO Auto-generated method stub  
        new MenuJframe();  
    }  
    //========面板控件   
	private JPanel menuJPanel;
	private JButton studentBtn,healthFormBtn,medicalChartBtn,writeOffBtn,staBtn; 
	public MenuJframe() {
		// TODO Auto-generated constructor stub
		super("菜单界面");
		studentBtn=new JButton("学生管理界面");
		healthFormBtn=new JButton("体检信息界面");
		medicalChartBtn=new JButton("病历信息界面");
		writeOffBtn=new JButton("注销");
		staBtn=new JButton("统计");
		//添加监听器
		studentBtn.addActionListener(this);
		studentBtn.setActionCommand("student"); 
		healthFormBtn.addActionListener(this);
		healthFormBtn.setActionCommand("healthForm"); 
		medicalChartBtn.addActionListener(this);
		medicalChartBtn.setActionCommand("medicalChart"); 
		writeOffBtn.addActionListener(this);
		writeOffBtn.setActionCommand("writeOff"); 
		staBtn.addActionListener(this);
		staBtn.setActionCommand("staBtn");
		//添加组件
		menuJPanel=new JPanel();
		menuJPanel.add(studentBtn);
		menuJPanel.add(healthFormBtn);
		menuJPanel.add(medicalChartBtn);
		menuJPanel.add(writeOffBtn);
		menuJPanel.add(staBtn);
		this.add(menuJPanel,BorderLayout.CENTER); 
		validate();
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setSize(800,100);
		this.setLocationRelativeTo(null);
		setVisible(true);
		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				if (JOptionPane.showConfirmDialog(MenuJframe.this, "是否注销？")==JOptionPane.OK_OPTION) {
					dispose();
					new MenuJframe();
				}
			}
		});
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if(e.getActionCommand().equals("student")) { 
			dispose();
			new StudentManage();         //学生管理界面
		}else if(e.getActionCommand().equals("healthForm")) { 
			dispose();
			new HealthformManage();
		}else if(e.getActionCommand().equals("medicalChart")) { 
			dispose();
			new MedicalchartManage();
		}else if (e.getActionCommand().equals("writeOff")) {
			dispose();
			new LoginJframe();
		}else if (e.getActionCommand().equals("staBtn")) {
			dispose();
			new StatisJframe();
		}
		
	}
	

}
